import gmpy2
import sympy


def is_both_truncatable(d):
    for i in range(len(str(d))):
        if not gmpy2.is_prime(int(str(d)[i:])):
            return False
        if not gmpy2.is_prime(int(str(d)[:i + 1])):
            return False
    return True


if __name__ == '__main__':
    num = []
    i = sympy.nextprime(10)
    while len(num) != 11:
        if i % 10 in [3, 7] and is_both_truncatable(i):
            num.append(i)
        i = sympy.nextprime(i)
    print(num)
    print(sum(num))
